'use strict';
let db = uniCloud.database();
let dbCmd = db.command;
exports.main = async (event, context) => {
 
 let projectInDB = await db.collection('projects').where({
	project:{
		_id:dbCmd.eq(event.project._id)
	} 
 }).get()
 
 if(projectInDB.affectedDocs !== 0 || projectInDB.data.length !== 0){
	 return{
		 status:2,
		 msg:"该项目已经存在"
	 }
 } else {
	 let finishCreateProjectRes = await db.collection('projects').add(event)
	 if(finishCreateProjectRes.affectedDocs !== 0){
	 	 return{
	 		 status:0,
	 		 msg:"创建成功"
	 	 }
	 }
 }
 
 return {
 	status: -1,
 	msg: "稍后重试"
 }
};
